<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
 <style type="text/css">          
body{height:2000px;background:#33C}
#test{position:relative; width:90%; height:30px;background:#ddd;top:200px;position:absolute}
</style>
</head>
<body>
天津你好<br/>
天津你好<br/>
天津你好<br/>
天津你好<br/>
天津你好<br/>
天津你好<br/>
<div id="test">滚动试试</div>
<script type="text/javascript">
function toolbar(el) {
el = typeof el == 'string' ? document.getElementById(el) : el;
var elTop = el.offsetTop;
var sTop = 0;
window.onscroll = function () {
sTop = document.body.scrollTop || document.documentElement.scrollTop;
if (sTop > elTop) {
el.style.top = "0";
el.style.position = "fixed"
} else {
el.style.top = elTop + 'px';
el.style.position = "absolute"

}
}
}
toolbar('test');
</script>
</body>
</html>
